OPC Studio User's Guide and Reference
Examples - Reactive Programming - Transfer of OPC Data Access item values

In the example below, your application is required to continuously monitor the value of an OPC item, and when it is available (there is no failure obtaining the value), make some computations with it (we will multiply the value by 1000), and write the results into a different OPC item. This logic can be expressed by following code:

DAItemChangedObservable.Create<int>(
         "", "OPCLabs.KitServer.2", "Simulation.Incrementing (1 s)", 100)
     .Where(e => e.Exception == null)
     .Select(e => e.Vtq.Value * 1000)
     .Subscribe(DAWriteItemValueObserver.Create<int>(
         "", "OPCLabs.KitServer.2", "Simulation.Register_I4"));

Let’s dissect what this example does:

  1. It creates an observable sequence for significant changes in OPC-DA item "Simulation.Incrementing (1 s)".
  2. The “Where” clause filters (from the observable sequence) only the changes that have a null Exception, i.e. those that carry a valid DAVtq object (value/timestamp/quality).
  3. The “Select” clause takes the actual value from the Vtq property (it is of type DAVtq<int>), and returns the value multiplied by 1000.
  4. An observer that writes incoming vales into the “Simulation.Register_I4” OPC-DA item is created.
  5. The observer is subscribed to the transformed (processed) observable sequence.

 

See Also

Conceptual